﻿#region Copyright (c) Lokad 2010
// This code is released under the terms of the new BSD licence.
// URL: http://www.lokad.com/
#endregion

using System.Web.Mvc;
using Lokad.Monitoring.BusinessLogic;
using Lokad.Monitoring.Persistence.Entities;
using Lokad.Monitoring.Persistence.Repositories;

namespace Lokad.Monitoring.Controllers
{
    [AuthorizeOrRedirect]
    public class UserController : Controller
    {
        private readonly UserRepository _users;

        public UserController()
        {
            _users = GlobalSetup.Container.Resolve<UserRepository>();
        }

        public ActionResult Index()
        {
            return View(_users.List());
        }

        public ActionResult Delete(long id)
        {
            _users.Delete(id);
            return RedirectToAction("Index");
        }

        public ActionResult Create()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(User user)
        {
            _users.Create(user);
            return RedirectToAction("Index");
        }
    }
}
